package com.tmxk.days01.carrental_wmh;

import java.util.Scanner;

/**
 * 汽车租赁管理类(RentMgrSys)对业务数据进行测试
 * @author Administrator
 *
 */
public class RentMgrSys {

    public static void main(String[] args)  throws Exception{

        try{


            getNullException();


        }catch (NullPointerException e){


            System.out.println("捕捉到的异常：" + e.getMessage());


        }


    }




    public static void getNullException(){


        String s = null;


        try{


            s = s.replace("a","");


        }catch (Exception e){


            throw new NullPointerException();



    }

        //创建Scanner键盘输入对象
        Scanner sc = new Scanner(System.in);
        //1.实例化MotoOperation业务类
        MotoOperation moOperation = new MotoOperation();
        //2.调用初始化机动车信息
        MotoVehicle[] motoVehicles = moOperation.initMotoVehicle();
        // null操作任意属性和方法 就会报   java.lang.NullPointerException  空指针异常
        // 循环遍历
		/*for (MotoVehicle c : motoVehicles) {
			if ( c != null) {
				System.out.println(c.toString());
			}
		}*/
        //提示用户输入
        System.out.println(">>>>>>>>>>>>>>>>>>>欢迎光临天马星空租赁平台>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        System.out.print("1、轿车	2、客车	3、卡车");
        System.out.print("\n请选择要租赁的汽车类型:");
        String motoType = sc.next();
        // 轿车对象
        Car car = null;
        // 如果var为null，则初始化为""
        //Object car = null;
        //Optional.ofNullable(car).orElse("");
        //Object bus = null;
        //Optional.ofNullable(bus).orElse("");
        // 轿车品牌变量
        String brandType = "";
        // 轿车型号
        String type = "";
        //客车对象
        Bus bus = null;
       //卡车对象
        Truck truck = null;



        //根据汽车租赁类型进行选项判定
        switch(motoType){
            case "1":
                car = new Car();
                System.out.print("请选择要租赁的汽车品牌: 1、别克	2、宝马 ");
                brandType = sc.next();
                if ("1".equals(brandType)) {
                    System.out.print("请选择要租赁的汽车型号: 1、林荫大道	 2、GL8");
                    type = sc.next();
                    type = "1".equals(type) ? "林荫大道" : "GL8";
                }else if("2".equals(brandType)){
                    System.out.print("请选择要租赁的汽车型号: 1、X6	 2、550i");
                    type = sc.next();
                    type = "1".equals(type) ? "X6" : "550i";
                }else{
                    System.out.println("请选择选项1或者2");
                }
                ((Car) car).setType(type);
                brandType = "1".equals(brandType) ? "别克" : "宝马";
                car.setBrand(brandType);

                // 将获取的car信息 获取 对应的租金
                for (MotoVehicle motoVehicle : motoVehicles) {
                    if (motoVehicle instanceof Car) {
                        //System.out.println(motoVehicle);
                        Car c = (Car)motoVehicle;
                        // 根据 轿车品牌 + 轿车型号,确定 租赁价格和 车牌号
                        if(c.getBrand().equals(car.getBrand()) && c.getType().equals(car.getType())){
                            //System.out.println(c.getPerRent() + "\t" + c.getVehicleId());
                            car.setPerRent(c.getPerRent());
                            car.setVehicleId(c.getVehicleId());
                        }
                    }
                }
                break;
            case "2":
                bus = new Bus();
                System.out.print("请选择要租赁的汽车品牌: 1、金杯	2、金龙 ");
                brandType = sc.next();
                if ("1".equals(brandType)) {
                    System.out.print("请选择要租赁的汽车型号: 1、16座	 2、34座");
                    type = sc.next();
                    type = "1".equals(type) ? "16座" : "34座";
                }else{
                    System.out.println("请选择选项1或者2");
                }
                bus.setBrand(brandType);
                brandType = "1".equals(brandType) ? "金杯" : "金龙";
                bus.setBrand(brandType);

                // 将获取的car信息 获取 对应的租金
                for (MotoVehicle motoVehicle : motoVehicles) {
                    if (motoVehicle instanceof Bus) {
                        //System.out.println(motoVehicle);
                        Bus b = (Bus) motoVehicle;
                        // 根据 客车品牌 + 客车型号,确定 租赁价格和 车牌号
                        if (b.getBrand().equals(bus.getBrand()) && b.getBrand().equals(bus.getBrand())) {
                            //System.out.println(c.getPerRent() + "\t" + c.getVehicleId());
                            bus.setPerRent(b.getPerRent());
                            bus.setVehicleId(b.getVehicleId());
                        }
                    }
                }
                break;
            case "3":
                truck = new Truck();
                System.out.print("请选择要租赁的汽车品牌: 1、一汽解放	2、重庆红岩 ");
                brandType = sc.next();
                if ("1".equals(brandType)) {
                    System.out.print("请选择要租赁的汽车型号: 1、1吨	 2、2吨");
                    type = sc.next();
                    type = "1".equals(type) ? "1吨" : "2吨";
                }else{
                    System.out.println("请选择选项1或者2");
                }
                truck.setBrand(brandType);
                brandType = "1".equals(brandType) ? "一汽解放" : "重庆红岩";
                truck.setBrand(brandType);

                // 将获取的car信息 获取 对应的租金
                for (MotoVehicle motoVehicle : motoVehicles) {
                    if (motoVehicle instanceof Truck) {
                        //System.out.println(motoVehicle);
                        Truck t = (Truck) motoVehicle;
                        // 根据 卡车品牌 + 卡车型号,确定 租赁价格和 车牌号
                        if (t.getBrand().equals(truck.getBrand()) && t.getBrand().equals(truck.getBrand())) {
                            //System.out.println(c.getPerRent() + "\t" + c.getVehicleId());
                            truck.setPerRent(t.getPerRent());
                            truck.setVehicleId(t.getVehicleId());
                        }
                    }
                }
                break;
            default:
                break;
        }
        // 分析: 根据以上的switch分支机构能获取到 对应的汽车租赁基本情况

        System.out.print("请选择要租赁天数:");
        int days = sc.nextInt();
        float rentPrice =  car.calRent(days);
        System.out.println("分配给你的汽车牌号是:" + car.getVehicleId());
        System.out.println("你需要支付的租赁费用是:" + rentPrice +  "元");
    }

}







